package com.joysuch.wwyt.api.base.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.joysuch.wwyt.core.common.ajax.ResultBean;
import com.joysuch.wwyt.workflow.entity.WorkFlowScreenType;
import com.joysuch.wwyt.workflow.repository.WorkFlowScreenTypeDao;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Author:  feizhou
 * Date:    2022/10/17 11:01
 */
@Slf4j
@RestController
@Api(tags = "大屏-配置")
@RequestMapping("/api/base/screenTabConfig")
public class ScreenConfigController {
    @Autowired
    private WorkFlowScreenTypeDao workFlowScreenTypeDao;

    @RequestMapping("list")
    public ResultBean workFlowPage() {
        try {
            List<WorkFlowScreenType> all = workFlowScreenTypeDao.findAll();
            if (all != null) {
                all = all.stream().filter(e -> "0".equals(e.getDeleteFlag())).collect(Collectors.toList());
            } else {
                all = new ArrayList<>(0);
            }
            JSONArray jsonArray = new JSONArray();
            all.forEach(type -> {
                JSONObject obj = new JSONObject();
                obj.put("name", type.getTypeName());
                obj.put("code", type.getCode());
                obj.put("id", type.getId());
                jsonArray.add(obj);
            });
            return ResultBean.success(jsonArray);
        } catch (Exception e) {
            log.error("查询区域列表失败", e);
            return ResultBean.fail(101, "查询区域列表失败");
        }
    }
}
